//
//  XMConOpenBoxView.m
//  XunMi
//
//  Created by MacBook on 2024/4/30.
//  Copyright © 2024 TieZhu. All rights reserved.
//

#import "XMConOpenBoxView.h"
#import "XMConOpenBoxRuleView.h"

@interface XMConOpenBoxView ()
@property (nonatomic, strong) XMConOpenBoxRuleView *ruleView;
@end

@implementation XMConOpenBoxView

- (void)awakeFromNib {
    [super awakeFromNib];
    NSString *goldStr = kStringFormat(@"消耗%@金币", kGlobalVariables.appConfig.chat.blind_box_golds.stringValue);
    NSString *titleStr = kStringFormat(@"开盲盒\n%@", goldStr);
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:titleStr];
    
    [attStr addAttributes:@{
        NSFontAttributeName: [UIFont fontWithName:@"PingFangSC-Medium" size:18], NSForegroundColorAttributeName: UIColor.whiteColor
    } range:[titleStr rangeOfString:@"开盲盒"]];
    
    [attStr addAttributes:@{
        NSFontAttributeName: kUIFont(12), NSForegroundColorAttributeName: kHEX(@"#FFB7B7")
    } range:[titleStr rangeOfString:goldStr]];
    self.openButton.titleLabel.numberOfLines = 0;
    self.openButton.titleLabel.textAlignment = NSTextAlignmentCenter;
    [self.openButton setAttributedTitle:attStr forState:UIControlStateNormal];
}

- (void)setModel:(XMOpenboxModel *)model {
    _model = model;
    self.ruleView.model = model;
}

- (IBAction)showDesc:(id)sender {
    self.ruleView.hidden = !self.ruleView.hidden;
}

- (IBAction)close:(id)sender {
    [GKCover hideCover];
}

- (IBAction)open:(id)sender {
    if (self.openBlock) {
        self.openBlock();
    }
}

- (XMConOpenBoxRuleView *)ruleView {
    if (_ruleView == nil) {
        _ruleView = [XMConOpenBoxRuleView viewFromXib];
        _ruleView.size = CGSizeMake(kScreenWidth, kScreenHeight);
        _ruleView.hidden = YES;
        [self addSubview:_ruleView];
    }
    return _ruleView;
}

@end
